#!/bin/bash

#[root@sugon_test ~]# tree -L 2 /opt/
#/opt/
#├── apache-tomcat-7.0.69
#│   ├── bin
#│   ├── conf
#│   ├── lib
#│   ├── LICENSE
#│   ├── logs
#│   ├── NOTICE
#│   ├── RELEASE-NOTES
#│   ├── RUNNING.txt
#│   ├── temp
#│   ├── webapps
#│   └── work
#├── apes
#│   ├── bin
#│   ├── deps
#│   ├── disk
#│   └── README.md
#├── asr-collector-4.7.1-SNAPSHOT
#│   ├── conf
#│   ├── lib
#│   ├── libopucodec64.so
#│   ├── libopus.so.0
#│   ├── log
#│   └── startup.sh
#├── asr-monitor-4.7.0-SNAPSHOT
#│   ├── conf
#│   ├── lib
#│   ├── log
#│   └── startup.sh
#├── asr-service-4.7.0-SNAPSHOT
#│   ├── conf
#│   ├── lib
#│   ├── log
#│   ├── startup.bat
#│   └── startup.sh
#├── icp-job-2.2.4.2-SNAPSHOT
#│   ├── config
#│   ├── icp-job.jar
#│   ├── logs
#│   └── startup.sh
#├── icp-monitor
#│   ├── config
#│   ├── icp-monitor.jar
#│   ├── logs
#│   └── startup.sh
#├── icp-services
#│   ├── config
#│   ├── icp-services.jar
#│   ├── logs
#│   └── startup.sh
#├── icp-web-2.2.4.2-SNAPSHOT
#│   ├── config
#│   ├── icp-web.jar
#│   ├── logs
#│   └── startup.sh
#├── io-service
#│   ├── config
#│   ├── io-service.jar
#│   ├── logs
#│   └── startup.sh
#├── jdk1.8.0_101
#│   ├── bin
#│   ├── COPYRIGHT
#│   ├── db
#│   ├── include
#│   ├── javafx-src.zip
#│   ├── jre
#│   ├── lib
#│   ├── LICENSE
#│   ├── man
#│   ├── README.html
#│   ├── release
#│   ├── src.zip
#│   ├── THIRDPARTYLICENSEREADME-JAVAFX.txt
#│   └── THIRDPARTYLICENSEREADME.txt
#├── judge-service
#│   ├── config
#│   ├── judge-service.jar
#│   ├── logs
#│   └── startup.sh
#├── judge-web-2.2.4.2-SNAPSHOT
#│   ├── config
#│   ├── judge-web.jar
#│   ├── logs
#│   └── startup.sh
#├── libreoffice5.4
#│   ├── CREDITS.fodt
#│   ├── help
#│   ├── LICENSE
#│   ├── LICENSE.fodt
#│   ├── LICENSE.html
#│   ├── NOTICE
#│   ├── presets
#│   ├── program
#│   ├── readmes
#│   └── share
#├── LibreOffice_5.4.7.2_Linux_x86-64_rpm
#│   ├── install
#│   ├── readmes
#│   └── RPMS
#├── manage-2.2.4.2-SNAPSHOT
#│   ├── config
#│   ├── logs
#│   ├── manage.jar
#│   ├── startup.sh
#│   └── startup.sh.bak
#├── mongodb
#│   ├── conf
#│   ├── data
#│   ├── log
#│   └── mongo-3.2.3.image
#├── mysql -> /opt/mysql-5.6.27-linux-glibc2.5-x86_64/
#├── mysql-5.6.27-linux-glibc2.5-x86_64
#│   ├── bin
#│   ├── COPYING
#│   ├── data
#│   ├── docs
#│   ├── include
#│   ├── INSTALL-BINARY
#│   ├── lib
#│   ├── man
#│   ├── my.cnf
#│   ├── my-new.cnf
#│   ├── mysql-test
#│   ├── README
#│   ├── scripts
#│   ├── share
#│   ├── sql-bench
#│   └── support-files
#├── redis
#│   ├── conf
#│   ├── data
#│   ├── log
#│   └── redis-3.0.5.image
#├── temp
#├── tengine-2.3.0
#│   ├── client_body_temp
#│   ├── conf
#│   ├── fastcgi_temp
#│   ├── html
#│   ├── logs
#│   ├── proxy_temp
#│   ├── sbin
#│   ├── scgi_temp
#│   └── uwsgi_temp
#├── v2.7.6service
#│   ├── docs
#│   ├── sdk
#│   ├── service
#│   └── tools
#└── zookeeper
#    ├── conf
#    ├── data
#    ├── log
#    └── zookeeper-3.4.8.image
#
#105 directories, 50 files

zero=0

#启动点 结尾需为"/"
tomcatExec=/opt/apache-tomcat-7.0.69/bin/
libreofficeExec=/opt/libreoffice5.4/program/
asrServerExec=/opt/asr-service-4.7.0-SNAPSHOT/
asrCollectorExec=/opt/asr-collector-4.7.1-SNAPSHOT/
asrMonitorExec=/opt/asr-monitor-4.7.0-SNAPSHOT/
icpServicesExec=/opt/icp-services/
judgeServiceExec=/opt/judge-service/
ioServiceExec=/opt/io-service/
icpJobExec=/opt/icp-job-2.2.4.2-SNAPSHOT/
icpMonitorExec=/opt/icp-monitor/
icpWebExec=/opt/icp-web-2.2.4.2-SNAPSHOT/
judgeWebExec=/opt/judge-web-2.2.4.2-SNAPSHOT/
manageExec=/opt/manage-2.2.4.2-SNAPSHOT/

#端口号
tomcatPort=8080
libreofficePort=8980
#读取配置端口
asrServerPort=$(cat ${asrServerExec}conf/asr-service.properties | grep protocol.port | awk -F '=' '{print $2}')
asrCollectorPort=9188
asrMonitorPort=18080
icpServicesPort=$(cat ${icpServicesExec}config/application.yml | grep port | sed s/[[:space:]]//g | awk -F ":" '{print $2}')
judgeServicePort=$(cat ${judgeServiceExec}config/application.yml  | grep -w port | sed s/[[:space:]]//g | awk -F ":" '{print $2}')
ioServicePort=$(cat ${ioServiceExec}config/application.yml  | grep -w port | sed s/[[:space:]]//g | awk -F ":" '{print $2}')
#icpJobPort=$(cat ${icpJobExec}config/application.yml | grep -w port | sed s/[[:space:]]//g | awk -F ":" '{print $2}' | sed -n '1p')
icpMonitorPort=$(cat ${icpMonitorExec}config/application.yml | grep -w port | sed s/[[:space:]]//g | awk -F ":" '{print $2}')
icpWebPort=$(cat ${icpWebExec}config/application.yml | grep -w port | sed s/[[:space:]]//g | awk -F ":" '{print $2}')
judgeWebPort=$(cat ${judgeWebExec}config/application.yml | grep -w port | sed s/[[:space:]]//g | awk -F ":" '{print $2}')
managePort=$(cat ${manageExec}config/application.yml | grep -w port | sed s/[[:space:]]//g | awk -F ":" '{print $2}' | sed -n '1p')

#tomcat
tomcatStart(){
	#判断服务存在
	tomcatStatus=99
	netstat -ntlp | grep -w $tomcatPort >> /dev/null 2>&1 && tomcatStatus=$?   #-w精确匹配，排除掉18080端口
	if [ $tomcatStatus -eq $zero ];then
		echo "tomcat服务已经启动！PID是:" $(netstat -ntlp | grep -w $tomcatPort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动tomcat服务……"
		sh ${tomcatExec}startup.sh
		#进程
		sleep 5
		tomcatPid=$(netstat -ntlp | grep -w $tomcatPort | awk '{print $7}' | awk -F "/" '{print $1}')
		echo $(date) "tomcat启动，PID:"$tomcatPid
		echo $(date) "tomcat启动，Version:" $(curl localhost:$tomcatPort | grep title)
	fi
}


#libreoffice
libreofficeStart(){
	#判断服务存在
	libreofficeStatus=99
	netstat -ntlp | grep $libreofficePort >> /dev/null 2>&1 && libreofficeStatus=$?
	if [ $libreofficeStatus -eq $zero ];then
		echo "libreoffice服务已经启动！PID是:" $(netstat -ntlp | grep $libreofficePort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动libreoffice服务……"
		cd $libreofficeExec && ./soffice --headless --accept="socket,host=127.0.0.1,port=$libreofficePort,tcpNoDelay=1;urp;StarOffice.ServiceManager" --nofirststartwizard &
		#进程
		sleep 5
		libreofficePid=$(netstat -ntlp | grep ${libreofficePort} | awk '{print $7}' | awk -F "/" '{print $1}')
		echo $(date) "libreoffice启动，PID:" $libreofficePid
	fi
}


#asr-service
asrServiceStart(){
	#判断服务存在
	asrServiceStatus=99
	netstat -ntlp | grep $asrServerPort >> /dev/null 2>&1 && asrServiceStatus=$?
	if [ $asrServiceStatus -eq $zero ];then
		echo "asr-serveice服务已经启动！PID是:" $(netstat -ntlp | grep ${asrServerPort} | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动asr-service服务……"
		cd $asrServerExec && rm -rf ${asrServerExec}log/* && ./startup.sh

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${asrServerExec}log/asr-service.log | grep "$(date '+%F %H')" | grep "Message消息系统启动完成..." && asrServiceStatus=$?
			if [ $asrServiceStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $asrServiceStatus -eq $zero ];then
			echo "asr-service启动成功！"
			#进程
			asrServicePid=$(netstat -ntlp | grep ${asrServerPort} | awk '{print $7}' | awk -F "/" '{print $1}')
			echo $(date) "asr-service启动，PID:" $asrServicePid
		else
			echo "asr-service启动失败！"
			cat ${asrServerExec}conf/asr-service.properties
			exit
		fi
	fi
}

#asr-collector
asrCollectorStart(){
	#配置文件没写端口，初步判断端口为：9999 9998 9188
	#判断服务存在，三个端口都在
	asrCollectorStatus=99
	if [[ `netstat -ntlp | grep 9999` && `netstat -ntlp | grep 9998` && `netstat -ntlp | grep $asrCollectorPort` ]];then
		asrCollectorStatus=0
	fi
	if [ $asrCollectorStatus -eq $zero ];then
		echo "asr-collector服务已经启动！PID是：" $(netstat -ntlp | grep $asrCollectorPort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动asr-collector服务……"
		cd $asrCollectorExec && rm -rf ${asrCollectorExec}log/* && ./startup.sh

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${asrCollectorExec}log/asr-collector.log | grep "$(date '+%F %H')" | grep "AsrCollector服务实例启动完毕..." && asrCollectorStatus=$?
			if [ $asrCollectorStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $asrCollectorStatus -eq $zero ];then
			echo "asr-collector启动成功！"
			#进程,仅根据一个端口判断
			asrCollectorPid=$(netstat -ntlp | grep $asrCollectorPort | awk '{print $7}' | awk -F "/" '{print $1}')
			echo $(date) "asr-collector启动，PID:" $asrCollectorPid
		else
			echo "asr-collector启动失败！"
			cat ${asrCollectorExec}conf/collector.properties
			exit
		fi
	fi
}

#asr-monitor
asrMonitorStart(){
	#配置文件没写端口，初步判断端口为：18080
	#判断服务存在，三个端口都在
	asrMonitorStatus=99
	netstat -ntlp | grep $asrMonitorPort >> /dev/null 2>&1 && asrMonitorStatus=$?
	if [ $asrMonitorStatus -eq $zero ];then
		echo "asr-monitor服务已经启动！PID是：" $(netstat -ntlp | grep $asrMonitorPort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动asr-monitor服务……"
		cd $asrMonitorExec && rm -rf ${asrMonitorExec}log/* && ./startup.sh

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${asrMonitorExec}log/asr-monitor.log | grep "$(date '+%F %H')" | grep "AsrMonitor实例启动完毕..." && asrMonitorStatus=$?
			if [ $asrMonitorStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $asrMonitorStatus -eq $zero ];then
			echo "asr-monitor服务启动成功！"
			asrMonitorPid=$(netstat -ntlp | grep $asrMonitorPort | awk '{print $7}' | awk -F "/" '{print $1}')
			#进程,仅根据一个端口判断
			echo $(date) "asr-monitor启动，PID:" $asrMonitorPid
		else
			echo "asr-monitor服务启动失败！"
			cat ${asrMonitorExec}conf/monitor.properties
			exit
		fi
	fi
}

#icp-services
icpServicesStart(){
	#判断服务存在
	icpServicesStatus=99
	netstat -ntlp | grep $icpServicesPort >> /dev/null 2>&1 && icpServicesStatus=$?
	if [ $icpServicesStatus -eq $zero ];then
		echo "icp-services服务已经启动！PID是:" $(netstat -ntlp | grep $icpServicesPort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动icp-services服务……"
		cd $icpServicesExec && rm -rf ${icpServicesExec}logs/* && ./startup.sh start

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${icpServicesExec}logs/icp-service.log | grep "$(date '+%F %H')" | grep "AsrIcpServerApp 启动完成!" && icpServicesStatus=$?
			if [ $icpServicesStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $icpServicesStatus -eq $zero ];then
			echo "icp-services启动成功！"
			#进程
			icpServicesPid=$(netstat -ntlp | grep $icpServicesPort | awk '{print $7}' | awk -F "/" '{print $1}')
			echo $(date) "icp-services启动，PID:" $icpServicesPid
		else
			echo "icp-services启动失败！"
			cat ${icpServicesExec}config/application.yml && cat ${icpServicesExec}config/bootstrap.properties
			exit
		fi
	fi
}


#judge-service
judgeServiceStart(){
	#判断服务存在
	judgeServiceStatus=99
	netstat -ntlp | grep $judgeServicePort >> /dev/null 2>&1 && judgeServiceStatus=$?
	if [ $judgeServiceStatus -eq $zero ];then
		echo "judge-service服务已经启动！PID是:" $(netstat -ntlp | grep $judgeServicePort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动judge-service服务……"
		cd $judgeServiceExec && rm -rf ${judgeServiceExec}logs/* && ./startup.sh start

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${judgeServiceExec}logs/judge-service.log | grep "$(date '+%F %H')" | grep "AsrJudgeDubboServerApp 启动完成!" && judgeServiceStatus=$?
			if [ $judgeServiceStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $judgeServiceStatus -eq $zero ];then
			echo "judge-service启动成功！"
			#进程
			judgeServicePid=$(netstat -ntlp | grep $judgeServicePort | awk '{print $7}' | awk -F "/" '{print $1}')
			echo $(date) "judge-service启动，PID:" $judgeServicePid
		else
			echo "judge-service启动失败！"
			cat ${judgeServiceExec}config/application.yml && cat ${judgeServiceExec}config/bootstrap.properties
			exit
		fi
	fi
}


#io-service
ioServiceStart(){
	#判断服务存在
	ioServiceStatus=99
	netstat -ntlp | grep $ioServicePort >> /dev/null 2>&1 && ioServiceStatus=$?
	if [ $ioServiceStatus -eq $zero ];then
		echo "io-service服务已经启动！PID是:" $(netstat -ntlp | grep $ioServicePort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动io-service服务……"
		cd $ioServiceExec && rm -rf ${ioServiceExec}logs/* && ./startup.sh start

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${ioServiceExec}logs/io-service.log | grep "$(date '+%F %H')" | grep "AsrIcpIoServerApp 启动完成!" && ioServiceStatus=$?
			if [ $ioServiceStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $ioServiceStatus -eq $zero ];then
			echo "io-service启动成功！"
			#进程
			ioServicePid=$(netstat -ntlp | grep $ioServicePort | awk '{print $7}' | awk -F "/" '{print $1}')
			echo $(date) "io-service启动，PID:" $ioServicePid
		else
			echo "io-service启动失败！"
			cat ${ioServiceExec}config/application.yml && cat ${ioServiceExec}config/bootstrap.properties
			exit
		fi
	fi
}

#icp-job 服务出错
icpJobStart(){
	icpJobStatus=99
	ps -ef|grep "DappName=icp-job" | grep java >> /dev/null 2>&1 && icpJobStatus=$?
	if [ $icpJobStatus -eq $zero ];then
		echo "icp-job服务已经启动！PID是:"$(ps -ef|grep "DappName=icp-job" | grep root  | grep java | grep -v grep | awk '{print $2}')
	else
		echo "########## 启动icp-job服务……"
		cd $icpJobExec && rm -rf ${icpJobExec}logs/* && ./startup.sh start
		sleep 5
		ps -ef|grep "DappName=icp-job" | grep java && echo "icp-job启动成功" || echo "icp-job启动失败"
	fi
}

#icp-monitor
icpMonitorStart(){
	#判断服务存在
	icpMonitorStatus=99
	netstat -ntlp | grep $icpMonitorPort >> /dev/null 2>&1 && icpMonitorStatus=$?
	if [ $icpMonitorStatus -eq $zero ];then
		echo "icp-monitor服务已经启动！PID是:" $(netstat -ntlp | grep $icpMonitorPort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动icp-monitor服务……"
		cd $icpMonitorExec && rm -rf ${icpMonitorExec}logs/* && ./startup.sh start

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${icpMonitorExec}logs/icp-monitor.log | grep "$(date '+%F %H')" | grep "书记员、法官端、当事人端通用信息交互开始..." && icpMonitorStatus=$?
			if [ $icpMonitorStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $icpMonitorStatus -eq $zero ];then
			echo "icp-monitor启动成功！"
			#进程
			echo $(date) "icp-monitor启动，PID:" $(netstat -ntlp | grep $icpMonitorPort | awk '{print $7}' | awk -F "/" '{print $1}')
		else
			echo "icp-monitor启动失败！"
			cat ${icpMonitorExec}config/application.yml && cat ${icpMonitorExec}config/bootstrap.properties
			exit
		fi
	fi
}
#以上完成

#icp-web
icpWebStart(){
	#判断服务存在
	icpWebStatus=99
	netstat -ntlp | grep $icpWebPort >> /dev/null 2>&1 && icpWebStatus=$?
	if [ $icpWebStatus -eq $zero ];then
		echo "icp-web服务已经启动！PID是:" $(netstat -ntlp | grep $icpWebPort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动icp-web服务……"
		cd ${icpWebExec} && rm -rf ${icpWebExec}logs/* && ./startup.sh start

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${icpWebExec}logs/icp-web.log | grep "$(date '+%F %H')" | grep "AsrIcpWebApp 启动完成!" && icpWebStatus=$?
			if [ $icpWebStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $icpWebStatus -eq $zero ];then
			echo "icp-web启动成功！"
			#进程
			echo $(date) "icp-web启动，PID:" $(netstat -ntlp | grep $icpWebPort | awk '{print $7}' | awk -F "/" '{print $1}')
		else
			echo "icp-web启动失败！"
			cat ${icpWebExec}config/application.yml && cat ${icpWebExec}config/bootstrap.properties
			exit
		fi
	fi
}


#judge-web
judgeWebStart(){
	#判断服务存在
	judgeWebStatus=99
	netstat -ntlp | grep $judgeWebPort >> /dev/null 2>&1 && judgeWebStatus=$?
	if [ $judgeWebStatus -eq $zero ];then
		echo "judge-web服务已经启动！PID是:" $(netstat -ntlp | grep $judgeWebPort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动judge-web服务……"
		cd ${judgeWebExec} && rm -rf ${judgeWebExec}logs/* && ./startup.sh start

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${judgeWebExec}logs/judge-web.log | grep "$(date '+%F %H')" | grep "AsrJudgeWebApp 启动完成!" && judgeWebStatus=$?
			if [ $judgeWebStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $judgeWebStatus -eq $zero ];then
			echo "judge-web启动成功！"
			#进程
			echo $(date) "judge-web启动，PID:" $(netstat -ntlp | grep $judgeWebPort | awk '{print $7}' | awk -F "/" '{print $1}')
		else
			echo "judge-web启动失败！"
			cat ${judgeWebExec}config/application.yml && cat ${judgeWebExec}config/bootstrap.properties
			exit
		fi
	fi
}

#manage
manageStart(){
	#判断服务存在
	manageStatus=99
	netstat -ntlp | grep $managePort >> /dev/null 2>&1 && manageStatus=$?
	if [ $manageStatus -eq $zero ];then
		echo "manage服务已经启动！PID是:" $(netstat -ntlp | grep $managePort | awk '{print $7}' | awk -F "/" '{print $1}')
	else
		echo "########## 启动manage服务……"
		cd $manageExec && rm -rf ${manageExec}logs/* && ./startup.sh start

		#通过日志判断启动结果
		for ((i=1; i<=24; i++)); do    #读取24*3秒的日志，超时就会提示启动失败
			sleep 3
			cat ${manageExec}logs/manage.log | grep "$(date '+%F %H')" | grep "AppManageApplication 启动完成!" && manageStatus=$?
			if [ $manageStatus -eq $zero ];then
				break
			fi
		done
		#为了处理失败，再判断一次
		if [ $manageStatus -eq $zero ];then
			echo "manage启动成功！"
			#进程
			echo $(date) "manage启动，PID:" $(netstat -ntlp | grep $managePort | awk '{print $7}' | awk -F "/" '{print $1}')
		else
			echo "manage启动失败！"
			cat ${manageExec}config/application.yml && cat ${manageExec}config/bootstrap.properties
			exit
		fi
	fi
}

#服务检查
serverCheck(){
  netstat -ntlp | grep -w $tomcatPort >> /dev/null 2>&1 && echo "tomcat runing" || echo -e "\e[1;31m tomcat not runing \e[0m"
  netstat -ntlp | grep $libreofficePort >> /dev/null 2>&1 && echo "libreoffice runing" || echo -e "\e[1;31m libreoffice not runing \e[0m"
  netstat -ntlp | grep $asrServerPort >> /dev/null 2>&1 && echo "asrServer runing" || echo -e "\e[1;31m asrServer not runing \e[0m"
  netstat -ntlp | grep $asrCollectorPort >> /dev/null 2>&1 && echo "asrCollector runing" || echo -e "\e[1;31m asrCollector not runing \e[0m"
  netstat -ntlp | grep $asrMonitorPort >> /dev/null 2>&1 && echo "asrMonitor runing" || echo -e "\e[1;31m asrMonitor not runing \e[0m"
  netstat -ntlp | grep $icpServicesPort >> /dev/null 2>&1 && echo "icpServices runing" || echo -e "\e[1;31m icpServices not runing \e[0m"
  netstat -ntlp | grep $judgeServicePort >> /dev/null 2>&1 && echo "judgeService runing" || echo -e "\e[1;31m judgeService not runing \e[0m"
  netstat -ntlp | grep $ioServicePort >> /dev/null 2>&1 && echo "ioService runing" || echo -e "\e[1;31m ioService not runing \e[0m"
  #netstat -ntlp | grep $icpJobPort >> /dev/null 2>&1 && echo "icpJob runing" || echo -e "\e[1;31m icpJob not runing \e[0m"
  ps -ef|grep "DappName=icp-job"| grep java >> /dev/null 2>&1 && echo "icpJob runing" || echo -e "\e[1;31m icpJob not runing \e[0m"
  netstat -ntlp | grep $icpWebPort >> /dev/null 2>&1 && echo "icpWeb runing" || echo -e "\e[1;31m icpWeb not runing \e[0m"
  netstat -ntlp | grep $judgeWebPort >> /dev/null 2>&1 && echo "judgeWeb runing" || echo -e "\e[1;31m judgeWeb not runing \e[0m"
  netstat -ntlp | grep $managePort>> /dev/null 2>&1 && echo "manage runing" || echo -e "\e[1;31m manage not runing \e[0m"
}
case $1 in
  "start")
    #运行 共十三个
    tomcatStart
    libreofficeStart

    asrServiceStart
    asrCollectorStart
    asrMonitorStart

    icpServicesStart
    judgeServiceStart
    ioServiceStart
    icpJobStart
    icpMonitorStart
    icpWebStart
    judgeWebStart
    manageStart
    ;;
 "stop")
    kill -9 $(netstat -ntlp | grep -w $tomcatPort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $libreofficePort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep ${asrServerPort} | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $asrCollectorPort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $asrMonitorPort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $icpServicesPort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $judgeServicePort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $ioServicePort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(ps -ef|grep "DappName=icp-job" | grep root  | grep java | grep -v grep | awk '{print $2}')
    kill -9 $(netstat -ntlp | grep $icpMonitorPort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $icpWebPort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $judgeWebPort | awk '{print $7}' | awk -F "/" '{print $1}')
    kill -9 $(netstat -ntlp | grep $managePort | awk '{print $7}' | awk -F "/" '{print $1}')
  ;;
 "status")
    serverCheck
 ;;
esac